﻿namespace ExamV5.GradeInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmPrintGrade : Page
    {
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Image ImageUser;
        protected Image ImageUserA;
        protected Label Label1;
        protected Label Label10;
        protected Label Label12;
        protected Label Label14;
        protected Label Label16;
        protected Label Label18;
        protected Label Label19;
        protected Label Label2;
        protected Label Label3;
        protected Label Label4;
        protected Label Label5;
        protected Label Label6;
        protected Label Label8;
        protected Label labExamDate;
        protected Label labExamDateA;
        protected Label labExamNameTip;
        protected Label labGrade;
        protected Label labGradeA;
        protected Label labGradeTip;
        protected Label labManagerQZ;
        protected Label labSubjectTip;
        protected Label labTip;
        protected Label labTipA;
        protected Label labUnitName;
        protected Label labUnitNameA;
        protected Label labUserCode;
        protected Label labUserCodeA;
        protected Label labUserCodeTip;
        protected Label labUserGWName;
        protected Label labUserGWNameA;
        protected Label labUserName;
        protected Label labUserNameA;
        protected Label labUserNameTip;
        protected Label labUserQZ;
        protected Label labUserSex;
        protected Label labUserSexA;
        protected Label labWorker;
        protected Label labWorkerA;
        private PublicFun publicFun_0 = new PublicFun();

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            string cmdText = "";
            int num = Convert.ToInt32(base.Request["ID"].ToString());
            string str2 = base.Server.UrlDecode(base.Request["UserCode"].ToString());
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (!base.IsPostBack)
                {
                    this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---打印考试成绩单";
                    if (this.publicFun_0.ReturnPaperData() != "Yes")
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')</script>");
                    }
                    else if (!((this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsAllowPrint'", "ParmValue").Trim() == "N") ? !(this.httpCookie_2.Value == "A") : true))
                    {
                        base.Response.Write("<script>alert('权限不足，不能打印成绩单！')</script>");
                    }
                    else
                    {
                        cmdText = string.Concat(new object[] { "select c.UPID,c.DeptName,a.LastDate,b.UserPhoto,b.UserGWName,b.UserSex,b.Worker,a.UserCode,a.Subject,a.GetCountFen,a.ExamName,b.UserName from ExamUser a,UserInfo b,DeptInfo c where b.DeptID=c.ID and a.UserCode=b.UserCode and a.PaperID=", num, " and a.UserCode='", str2, "'" });
                        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                        connection.Open();
                        SqlDataReader reader = new SqlCommand(cmdText, connection).ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            this.labUserCodeA.Text = reader["UserCode"].ToString();
                            this.labUserNameA.Text = reader["UserName"].ToString();
                            this.labTipA.Text = reader["ExamName"].ToString() + "成绩单";
                            this.labGradeA.Text = reader["GetCountFen"].ToString();
                            this.labUserGWName.Text = reader["UserGWName"].ToString();
                            this.labUserGWNameA.Text = reader["UserGWName"].ToString();
                            this.labUserCode.Text = reader["UserCode"].ToString();
                            this.labUserName.Text = reader["UserName"].ToString();
                            this.labTip.Text = reader["ExamName"].ToString() + "成绩单";
                            this.labGrade.Text = reader["GetCountFen"].ToString();
                            string str4 = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsGradeStand'", "ParmValue").Trim();
                            if (!(str4 == "") ? !(str4 == "Y") : false)
                            {
                                this.labGrade.Text = this.labGrade.Text + "分";
                                this.labGradeA.Text = this.labGradeA.Text + "分";
                            }
                            else
                            {
                                double num2 = Convert.ToDouble(reader["GetCountFen"].ToString());
                                string values = this.publicFun_0.GetValues(string.Concat(new object[] { "select ReuleName from GradeReule where PaperID=", num, " and MinValue<=", num2, " and ", num2, "<=MaxValue" }), "ReuleName");
                                if (values.Trim() == "")
                                {
                                    values = this.publicFun_0.GetValues(string.Concat(new object[] { "select ReuleName from GradeReule where PaperID=0 and MinValue<=", num2, " and ", num2, "<=MaxValue" }), "ReuleName");
                                    if (values.Trim() == "")
                                    {
                                        values = "未定义";
                                    }
                                }
                                this.labGrade.Text = this.labGrade.Text + "分<font color=red>(" + values + ")</font>";
                                this.labGradeA.Text = this.labGradeA.Text + "分<font color=red>(" + values + ")</font>";
                            }
                            this.labUserSex.Text = reader["UserSex"].ToString();
                            this.labWorker.Text = reader["Worker"].ToString();
                            this.labExamDate.Text = reader["LastDate"].ToString();
                            if (!(reader["UPID"].ToString().Trim() == "0"))
                            {
                                this.labUnitName.Text = this.publicFun_0.GetValues("select DeptName from DeptInfo where ID=" + reader["UPID"].ToString().Trim(), "DeptName") + @"\" + reader["DeptName"].ToString().Trim();
                            }
                            else
                            {
                                this.labUnitName.Text = reader["DeptName"].ToString();
                            }
                            this.labUnitNameA.Text = this.labUnitName.Text;
                            this.labUserSexA.Text = reader["UserSex"].ToString();
                            this.labWorkerA.Text = reader["Worker"].ToString();
                            this.labExamDateA.Text = reader["LastDate"].ToString();
                            if (reader["UserPhoto"].ToString().Trim() == "")
                            {
                                this.ImageUser.ImageUrl = "../publicFile/SysUserImg.gif";
                                this.ImageUserA.ImageUrl = "../publicFile/SysUserImg.gif";
                            }
                            else
                            {
                                this.ImageUser.ImageUrl = "../publicFile/" + reader["UserPhoto"].ToString();
                                this.ImageUserA.ImageUrl = "../publicFile/" + reader["UserPhoto"].ToString();
                            }
                        }
                        reader.Close();
                        connection.Close();
                        connection.Dispose();
                        base.Response.Write("<script>setTimeout(function(){ if (confirm('确定要打印成绩单吗？')) { window.print();} },1000)</script>");
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

